import { Module } from '@nestjs/common';
import { IconListService } from './icon-list.service';
import { IconListController } from './icon-list.controller';
import { IconList } from './entities/icon-list.entity';
import { IconGroupList } from './entities/iconGroup-list.entity';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MulterModule } from '@nestjs/platform-express';
import { extname, join } from 'path';
import { diskStorage } from 'multer';

@Module({
  imports: [
    TypeOrmModule.forFeature([IconList, IconGroupList]),
    MulterModule.register({
      // 用于配置上传，这部分也可以写在路由上
      storage: diskStorage({
        // destination: join(__dirname, '../images'),
        destination: join('./public/uploaded/icons'),
        filename: (_, file, callback) => {
          file.originalname = Buffer.from(file.originalname, "latin1").toString(
            "utf8"
          );
          const fileName = `${
            new Date().getTime() + extname(file.originalname)
          }`;
          return callback(null, fileName);
        },
      }),
    }),
  ],
  controllers: [IconListController],
  providers: [IconListService],
})
export class IconListModule {}
